<%-- 
    Document   : moveOut
    Created on : Jun 4, 2013, 4:51:59 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>List des étudiants</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <%
                        if (session.getAttribute("username") == null || !session.getAttribute("username").equals("admin")) {%>
                    Connectez-vous comme l'administrator, s'il vous plaît
                    <% } else if (session.getAttribute("username").equals("admin")) {
                        String sql = "SELECT username, firstname, lastname, birthday, email, status, r_number FROM account WHERE username!='admin' ORDER BY lastname";
                        rs = stmt.executeQuery(sql);%>
                    <table align="center" width="100%"><tr>
                            <th>USR</th>
                            <th>NOM</th>
                            <th>PRENOM</th>
                            <th>ANNIVERSAIRE</th>
                            <th>COURRIEL</th>
                            <th colspan="2" style="text-align: center">GERER</th></tr>
                                <% while (rs.next()) {
                                        String usr = rs.getString("username");
                                        String status = rs.getString("status");
                                        String room = rs.getString("r_number");%>
                        <tr>
                            <td><%= usr%></td>
                            <td><%= rs.getString("lastname")%></td>
                            <td><%= rs.getString("firstname")%></td>
                            <td><%= rs.getString("birthday")%></td>
                            <td><%= rs.getString("email")%></td>
                            <td>
                                <% if (room != null) {%>
                                <form method="get" action="changeRoom.jsp" name="updateInfo">
                                    <input type="hidden" name="selectedUsr" value="<%= usr%>"/>
                                    <input type="submit" name="selectButton" value="Change Room"/>
                                </form>
                                <% }%>
                            </td>
                            <td>
                                <form method="post" action="Update" name="updateInfo">
                                    <input type="hidden" name="typeMss" value="moveOut"/>
                                    <input type="hidden" name="deleteUsr" value="<%= usr%>"/>
                                    <input type="hidden" name="usrStatus" value="<%= status%>"/>
                                    <% if (status.equals("1")) {%>
                                    <input type="submit" name="deleteButton" value="Delete"/>
                                    <% } else {%>
                                    <input type="submit" name="deleteButton" value="Active"/>
                                    <% }%>
                                </form>
                            </td>
                        </tr>
                        <% }
                            }%>
                    </table>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>
